package gui;

import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class BackgroundPanel extends JPanel
{
	private static final long serialVersionUID = 1L;
	
	Image image;

	  public BackgroundPanel(String location)
	  {
	    try
	    {
	    	// Get image from location
	    	this.image = new ImageIcon(location).getImage();
	    }
	    catch (Exception e)
	    {
	    	System.out.println("ERROR: Could not find location.");
	    }
	  }

	  public void paintComponent(Graphics g)
	  {
	    super.paintComponent(g);

	    if (this.image != null)
	    {
	    	// Fill image in complete panel
	    	g.drawImage(this.image, getWidth() / 2 - this.image.getWidth(this) / 2, getHeight() / 2 - this.image.getHeight(this) / 2, this.image.getWidth(this), this.image.getHeight(this), this);
	    }
	  }
}
